package com.android.happymall.adapt;

import android.content.Context;
import android.graphics.Paint;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.happymall.model.group.MainList;
import com.android.happymall.utils.ObjectUtils;
import com.android.happymall.R;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class MainlistAdapt extends BaseMultiItemQuickAdapter<MainList.MainListdata.Mainlistdata, BaseViewHolder> {
    private String type;

    public MainlistAdapt(Context context, List<MainList.MainListdata.Mainlistdata> data, String type) {
        super(data);
        this.type = type;
        addItemType(MainList.MainListdata.Mainlistdata.ONE, R.layout.item_list_main);
        addItemType(MainList.MainListdata.Mainlistdata.DOUBLE, R.layout.item_grid_detail_like);
        addItemType(MainList.MainListdata.Mainlistdata.THREE, R.layout.item_grid_aishangmainpage);
    }

    @Override
    protected void convert(BaseViewHolder holder, MainList.MainListdata.Mainlistdata mainlistdata) {
        switch (holder.getItemViewType()) {
            case MainList.MainListdata.Mainlistdata.THREE:
                break;
            case MainList.MainListdata.Mainlistdata.DOUBLE:
                ((TextView) holder.getView(R.id.item_grid_detail_like_number_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                holder.setText(R.id.item_grid_detail_like_title, mainlistdata.getName());
                holder.setText(R.id.item_grid_detail_like_number_after, "￥" + mainlistdata.getTeam_price());
                holder.setText(R.id.item_grid_detail_like_number_before, "￥" + mainlistdata.getPrice());
                holder.setText(R.id.item_grid_detail_like_tuanshu, mainlistdata.getTeam_people_num() + "人参团");
                ObjectUtils.photo2(mContext, mainlistdata.getThumb(), ((ImageView) holder.getView(R.id.item_grid_detail_like_img)));
                break;
            case MainList.MainListdata.Mainlistdata.ONE:
                ((TextView) holder.getView(R.id.item_list_sort_aa_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                ObjectUtils.photo2(mContext, mainlistdata.getThumb(), ((ImageView) holder.getView(R.id.main_list_item_image)));
                holder.setText(R.id.main_list_item_count, mainlistdata.getDiscount_price() + "折");
                holder.setText(R.id.main_list_item_tuannumber, mainlistdata.getTeam_num() + "人团");
                holder.setText(R.id.ll_start_soon_num, mainlistdata.getTeam_num() + "人团");
                holder.setText(R.id.ll_free_num, mainlistdata.getTeam_num() + "人团");
                holder.setText(R.id.main_list_item_alltuannumber2, "已团" + mainlistdata.getTeam_people_num() + "件");
                String price1 = mainlistdata.getTeam_price();
                SpannableString msp = new SpannableString("￥" + price1);
                msp.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                holder.setText(R.id.main_list_item_money_after, msp);
                ((TextView) holder.getView(R.id.main_list_item_money_before)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                holder.setText(R.id.main_list_item_money_before, "￥" + mainlistdata.getPrice());
                int endtime = Integer.parseInt(mainlistdata.getEnd_time());
                final int starttime = Integer.parseInt(mainlistdata.getStart_time());
                final int run_time = mainlistdata.getRun_time();
                switch (mainlistdata.getTypeid()) {
                    case "1":
                        holder.setText(R.id.title_type, "拼团");
                        holder.setText(R.id.main_list_item_title, "             " + mainlistdata.getName());
                        break;
                    case "2":
                        holder.setText(R.id.title_type, "新人专享");
                        holder.setText(R.id.main_list_item_title, "                     " + mainlistdata.getName());
                        break;
                    case "3":
                        holder.setText(R.id.title_type, "限时秒杀");
                        holder.setText(R.id.main_list_item_title, "                     " + mainlistdata.getName());
                        break;
                    case "4":
                        holder.setText(R.id.title_type, "限时秒杀");
                        holder.setText(R.id.main_list_item_title, "                     " + mainlistdata.getName());
                        break;
                    case "5":
                        holder.setText(R.id.title_type, "免费试用");
                        holder.setText(R.id.main_list_item_title, "                     " + mainlistdata.getName());
                        break;
                    case "6":
                        holder.setText(R.id.title_type, "抽奖");
                        holder.setText(R.id.main_list_item_title, "             " + mainlistdata.getName());
                        break;
                    case "7":
                        holder.setText(R.id.title_type, "AA团");
                        holder.setText(R.id.main_list_item_title, "             " + mainlistdata.getName());

                        break;
                    case "8":
                        holder.setText(R.id.title_type, "推广团");
                        holder.setText(R.id.main_list_item_title, "                 " + mainlistdata.getName());

                        break;
                    case "9":
                        holder.setText(R.id.title_type, "自选团");
                        holder.setText(R.id.main_list_item_title, "                 " + mainlistdata.getName());
                        break;
                    case "10":
                        holder.setText(R.id.title_type, "阶梯团");
                        holder.setText(R.id.main_list_item_title, "                 " + mainlistdata.getName());
                        break;
                }

                String strendTime;
                switch (type) {
                    case "3":
                        holder.setText(R.id.main_list_item_count, "试用");
                        holder.setVisible(R.id.item_list_sort_lottory_time, true);
                        strendTime = ObjectUtils.getStrTime(mainlistdata.getEnd_time(), "MM月dd日 HH:mm");
                        holder.setText(R.id.item_list_sort_lottory_time, "截止时间" + strendTime);
                        holder.setVisible(R.id.main_list_item_stock, true);
                        if (run_time > endtime && run_time > starttime) {
                            holder.setText(R.id.main_list_item_stock, "活动已经结束");
                            holder.setVisible(R.id.ll_result, true);
                            holder.setVisible(R.id.ll_free, false);
                            holder.setVisible(R.id.ll_start_soon, false);
                        } else if (run_time > starttime && run_time < endtime) {
                            holder.setText(R.id.main_list_item_stock, "限量" + mainlistdata.getLuck_num() + "件");
                            holder.setVisible(R.id.ll_result, false);
                            holder.setVisible(R.id.ll_free, true);
                            holder.setVisible(R.id.ll_start_soon, false);
                        } else if (run_time < starttime) {
                            holder.setText(R.id.main_list_item_stock, "限量" + mainlistdata.getLuck_num() + "件");
                            holder.setVisible(R.id.ll_result, false);
                            holder.setVisible(R.id.ll_free, false);
                            holder.setVisible(R.id.ll_start_soon, true);
                        }
                        holder.setText(R.id.main_list_item_alltuannumber2, "￥" + mainlistdata.getPrice());
                        ((TextView) holder.getView(R.id.main_list_item_alltuannumber2)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                        break;
                    case "6":
                        holder.setText(R.id.main_list_item_count, "抽奖");
                        holder.setVisible(R.id.item_list_sort_lottory_time, true);
                        strendTime = ObjectUtils.getStrTime(mainlistdata.getEnd_time(), "MM月dd日 HH:mm");
                        holder.setText(R.id.item_list_sort_lottory_time, "截止时间" + strendTime);
                        if (run_time > endtime && run_time > starttime) {
                            holder.setVisible(R.id.ll_result, true);
                            holder.setVisible(R.id.main_list_item_go_kai, false);
                            holder.setVisible(R.id.ll_start_soon, false);
                        } else if (run_time > starttime && run_time < endtime) {
                            holder.setVisible(R.id.ll_result, false);
                            holder.setVisible(R.id.main_list_item_go_kai, true);
                            holder.setVisible(R.id.ll_start_soon, false);
                        } else if (run_time < starttime) {
                            holder.setVisible(R.id.ll_result, false);
                            holder.setVisible(R.id.main_list_item_go_kai, false);
                            holder.setVisible(R.id.ll_start_soon, true);
                        }
                        holder.setText(R.id.main_list_item_alltuannumber2, "￥" + mainlistdata.getPrice());
                        ((TextView) holder.getView(R.id.main_list_item_alltuannumber2)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                        break;
                    case "7":
                        holder.setVisible(R.id.ll_price_aa, true);
                        holder.setVisible(R.id.main_list_item_go_kai, true);
                        holder.setVisible(R.id.ll_price_normal, false);
                        SpannableString msp_aa = new SpannableString("￥" + mainlistdata.getTeam_price());
                        msp_aa.setSpan(new AbsoluteSizeSpan(13, true), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        holder.setText(R.id.item_list_sort_aa_total, msp_aa);
                        holder.setText(R.id.item_list_sort_aa_before, "￥" + mainlistdata.getPrice());
                        holder.setText(R.id.item_list_sort_aa_tuanshu2, mainlistdata.getTeam_num() + "人团总价:");
                        double v = Double.parseDouble(price1);
                        int tuan = Integer.parseInt(mainlistdata.getTeam_num());
                        String price = ObjectUtils.div(v, tuan, 2) + "";
                        String[] split = price.split("\\.");
                        if (split[1].equals("0")) {
                            price = split[0];
                        }
                        holder.setText(R.id.item_list_sort_aa_after, "每人" + price + "元");
                        break;
                    default:
                        holder.setVisible(R.id.main_list_item_go_kai, true);

                        break;

                }

                holder.addOnClickListener(R.id.main_list_item_go_kai)
                        .addOnClickListener(R.id.ll_free)
                        .addOnClickListener(R.id.ll_start_soon)
                        .addOnClickListener(R.id.ll_result);


                break;
        }

    }

}
